﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DBLClient.DBLUserOrganizationService;
namespace DBLClient.DBLForm
{
    public partial class EditUserOrganizationForm : Form
    {
        private int usermemberid;
        private string dblno;
        public EditUserOrganizationForm(int usermemberid,string dblno)
        {
            InitializeComponent();
            this.usermemberid = usermemberid;
            this.dblno = dblno;

            FillUserOrganizationInfo();
        }


        private void FillUserOrganizationInfo()
        {
            UserOrganizationService user = new UserOrganizationService();
            DataSet ds = user.FindOrganizationDetailByID(this.usermemberid);
            if (ds.Tables[0].Rows.Count != 0)
            {
                textBoxFullName.Text = ds.Tables[0].Rows[0]["fullname"].ToString();
                textBoxAddress.Text = ds.Tables[0].Rows[0]["address"].ToString();
                textBoxDescription.Text = ds.Tables[0].Rows[0]["description"].ToString();

                textBoxNickName.Text = ds.Tables[0].Rows[0]["nickname"].ToString();
                textBoxKeyword1.Text = ds.Tables[0].Rows[0]["keyword1"].ToString();
                textBoxKeyword2.Text = ds.Tables[0].Rows[0]["keyword2"].ToString();
                textBoxKeyword3.Text = ds.Tables[0].Rows[0]["keyword3"].ToString();
                textBoxQQ.Text = ds.Tables[0].Rows[0]["nickname"].ToString();
                textBoxPhone.Text = ds.Tables[0].Rows[0]["phone"].ToString();
                textBoxMSN.Text = ds.Tables[0].Rows[0]["msn"].ToString();
                textBoxWeibo.Text = ds.Tables[0].Rows[0]["weibo"].ToString();
                textBoxWebsite.Text = ds.Tables[0].Rows[0]["website"].ToString();
                textBoxMobilePhone.Text = ds.Tables[0].Rows[0]["mobilephone"].ToString();
                textBoxFax.Text = ds.Tables[0].Rows[0]["fax"].ToString();
                textBoxBlog.Text = ds.Tables[0].Rows[0]["blog"].ToString();
                textBoxEmail.Text = ds.Tables[0].Rows[0]["email"].ToString();
                textBoxDBLNo.Text = ds.Tables[0].Rows[0]["dblno"].ToString();
            }
        }

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            //基本信息
            string fullname = textBoxFullName.Text;
            string address = textBoxAddress.Text;
            string description = textBoxDescription.Text;

            //搜索信息
            string nickname = textBoxNickName.Text;
            string keyword1 = textBoxKeyword1.Text;
            string keyword2 = textBoxKeyword2.Text;
            string keyword3 = textBoxKeyword3.Text;

            //联系信息
            string qq = textBoxQQ.Text;
            string phone = textBoxPhone.Text;
            string msn = textBoxMSN.Text;
            string weibo = textBoxWeibo.Text;
            string website = textBoxWebsite.Text;
            string mobilephone = textBoxMobilePhone.Text;
            string fax = textBoxFax.Text;
            string blog = textBoxBlog.Text;
            string email = textBoxEmail.Text;

            UserOrganizationService user = new UserOrganizationService();
            int affectnum = user.AddUpdateUserOrganization(usermemberid, dblno, nickname, fullname, keyword1, keyword2, keyword3,
                address, description, phone, fax, email, mobilephone, qq, msn, blog, weibo, website);

            if (affectnum == 1)
            {
                MessageBox.Show("修改机构用户信息成功");
            }
            else
            {
                MessageBox.Show("修改机构用户信息失败");
            }
        }
    }
}
